java我可以用什么来代替AudioPlayer。游戏者停止();?
我已经成功地在GUI中编写了播放音频的代码
但是当我使用:
AudioPlayer.player.stop();
单词"
stop"
被划掉,并给出警告说java.lang.Thread
的方法stop(), suspend() and resume()
是危险的,不应使用我正在使用NetbeansIDE 6.9.1
我读过的所有网站使用这种方法都没有问题。是否有其他方法停止播放音频
这是我的代码:
String song = songList.getSelectedValue().toString();//determines the string of the selected value in the list box
if(song.equals("Matt Nathanson - Come On Get Higher")){//if this song is selected...
InputStream in;
try{
in = new FileInputStream(new File("C:\\Stuff\\Grade Twelve\\Computer Programming\\Unit 4\\Step 3\\GuitarForBeginners\\src\\guitarforbeginners\\resources\\Come On Get Higher.wav"));
AudioStream audio = new AudioStream(in);
AudioPlayer.player.start(audio);
}
catch(Exception e){
System.out.println("File not found");
}
if (cancelButton.isSelected()){
AudioPlayer.player.stop(audio);
}
}
(回复greg-449)
使用了您建议的链接以及http://www.javadocexamples.com/java_source/__/co/CoreJavaSound.java.html。程序运行但打印null
。思想??谢谢
if (song.equals("Matt Nathanson - Come On Get Higher")){//if this song is selected...
try{
stopPlay();
AudioInputStream audio = AudioSystem.getAudioInputStream(getClass().getResourceAsStream("C:\\Stuff\\Grade Twelve\\Computer Programming\\Unit 4\\Step 3\\GuitarForBeginners\\src\\guitarforbeginners\\resources\\Come On Get Higher.wav"));
clip = AudioSystem.getClip();
clip.open(audio);
clip.start();
} catch(Exception e){
stopPlay();
System.err.println(e.getMessage());
}
}
# 1 楼答案
你应该诅咒一个AudioPlayer对象,然后调用他的方法
***
# 2 楼答案
试试这个
其中,零秒wav是长度为零秒的wav